﻿#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <unistd.h>

#include "app/functions/md5.h"
#include "app/cJSON/cJSON.h"
#include "app/camera/hikvision.h"
#include "app/functions/tinyxml2.h"
#include "app/web/httpserver.h"

using namespace tinyxml2;


/*线程池*/
pthread_t tid[11] = { 0 };

int main()
{
    HikCamera::getInstance()->init("192.168.1.64", 80, "admin", "hik123456");
    //HikCamera::getInstance()->devInfo();

    int now_t = Timer::get_unix_timestamp();
    int rValue = Functions::random2(10, 99, now_t);

    std::string filePath = "./";
    filePath.append(std::to_string(now_t));
    filePath.append("_");
    filePath.append(std::to_string(rValue));
    filePath.append(".jpg");

    HikCamera::getInstance()->putCapture(1, filePath.c_str());

    //线程管理
    //int ret0 = pthread_create(&tid[0], NULL, HttpServer::http_server_pthread, NULL);  //WEB线程
  //  pthread_exit(NULL); //等待所有线程完毕

    return 0;
}

int main2()
{
    /*printf("%s 向你问好!\n", "Hikvision");

    char md5_str[50] = { 0 };
    char md5_src[] = "19870214";
    Md5::md5(md5_src, strlen(md5_src), md5_str);
    printf("md5_test1:%s\r\n", md5_str);


    char testchr[] = "qop=\"auth\", realm=\"IP Camera(J3036)\", nonce=\"326265323a31616638343838383a615bf81ef820463399cc83e705158951\", stale=\"FALSE\"";

    char nonceHeadChr[] = "nonce=\"";

    char* p = strstr(testchr, nonceHeadChr);

    if (p == NULL) { return -1; }
    p += strlen(nonceHeadChr);

    if (strlen(p) < 60) { return -1; }

    char nonceChr[61] = { 0 };
    memcpy(nonceChr, p, 60);
    std::cout << nonceChr << std::endl;

    return 0;*/
}

//std::string Char2Hex(char a)
//{
//    std::string str = "";
//    int n = a;
//    for (int i = 2 * sizeof(char) - 1; i >= 0; i--)
//    {
//        str += "0123456789ABCDEF"[((n >> i * 4) & 0xF)];
//    }
//    return str;
//}


